FROM node:20-alpine as builder

# ENV PNPM_HOME="/pnpm"
# ENV PATH="$PNPM_HOME:$PATH"
# RUN corepack enable

ENV NODE_ENV production
# 设置工作目录
# 复制应用程序源代码
WORKDIR /app
COPY . .

# 复制package.json和package-lock.json文件
# RUN npm config set strict-ssl false
# RUN npm config set registry https://registry.npmmirror.com/
# 安装npm依赖
RUN npm install


# 构建NestJS应用程序

RUN npm run build

# 第二阶段：使用一个轻量级的Node.js基础镜像来运行构建好的应用程序
FROM node:20-alpine


WORKDIR /app
# 复制构建好的应用程序
# COPY --from=builder /app .
# 设置工作目录

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/.production.env ./
# 暴露应用程序端口（如果需要）
EXPOSE 3003

ENV NODE_ENV production
# 运行NestJS应用程序
CMD ["node", "dist/main.js"]
